"""
@Project ：HD_project 
@File    ：http_utils.py
@IDE     ：PyCharm 
@Author  ：靓仔
@Date    ：2023/11/18 0018 15:57 
"""

import requests
from utils.log_control import INFO, ERROR


class CustomRequests:
    def __init__(self):
        self.session = requests.Session()





    def get(self, url, params=None, headers=None):
        try:
            # 使用 session.headers.update() 方法合并默认头部和传入的头部
            response = self.session.get(url, params=params, headers=headers)
            response.raise_for_status()
            return response
        except requests.exceptions.RequestException as e:
            ERROR.logger.error(f"Error in GET request: {e}")
            return None

    def post(self, url, data=None, json=None, headers=None):
        try:
            response = self.session.post(url, data=data, json=json, headers=headers)
            response.raise_for_status()
            return response
        except requests.exceptions.RequestException as e:
            ERROR.logger.error(f"Error in POST request: {e}")
            return None

    def close_session(self):
        self.session.close()
        INFO.logger.info("关闭当前会话！")
